// request对象其实是axios实例
import { Key } from 'react'
import { request } from '@/utils/http'

// 引入ts类型
import {
  IhospitalListParams,
  IhospitalListRes,
  IprovinceList,
  IhospitalShow,
  IdepartmentList,
  IsheduleRuleRes,
  IsheduleDetailList,
  Status,
} from './model/hospitalListTypes'
// 获取医院列表表格数据
// 注意: 由于参数很多,所以定义参数列表不是很方便,一般就会要求传入一个对象
// params就是一个存储了所有参数的对象
export const reqHospitalList = (params: IhospitalListParams) => {
  const {
    page,
    pageSize,
    hosname,
    hoscode,
    hostype,
    provinceCode,
    cityCode,
    districtCode,
    status,
  } = params
  return request.get<any, IhospitalListRes>(
    `/admin/hosp/hospital/${page}/${pageSize}`,
    {
      params: {
        hosname,
        hoscode,
        hostype,
        provinceCode,
        cityCode,
        districtCode,
        status,
      },
    }
  )
}

// 获取省数据的函数
export const reqProvince = (dictCode = 'province') => {
  return request.get<any, IprovinceList>(
    `/admin/cmn/dict/findByDictCode/${dictCode}`
  )
}

// 获取市或区数据的函数
// 如果要获取市数据,parentId就是省的编码
// 如果要获取区数据,parentId就是市的编码
export const reqCityOrDistrict = (parentId: string) => {
  // 省市数据结构一样,所以市数据也用之前省的数据类型
  return request.get<any, IprovinceList>(
    `/admin/cmn/dict/findByParentId/${parentId}`
  )
}

// 获取医院详情的函数
export function reqHospitalShow(id: string) {
  return request.get<any, IhospitalShow>(`/admin/hosp/hospital/show/${id}`)
}

// 获取指定医院的所有科室数据

export function reqdepartment(hoscode: string) {
  return request.get<any, IdepartmentList>(`/admin/hosp/department/${hoscode}`)
}

// 获取指定科室的排班规则数据
export function reqScheduleRules(
  page: number,
  pageSize: number,
  hoscode: string,
  depcode: string
) {
  return request.get<any, IsheduleRuleRes>(
    `/admin/hosp/schedule/getScheduleRule/${page}/${pageSize}/${hoscode}/${depcode}`
  )
}

// 获取排班详细信息的函数
export function reqScheduleList(
  hoscode: string,
  depcode: string,
  workDate: string
) {
  return request.get<any, IsheduleDetailList>(
    `/admin/hosp/schedule/findScheduleList/${hoscode}/${depcode}/${workDate}`
  )
}

// 更新医院上下线状态
export function reqHospitalStatus(id: string, status: Status) {
  return request.get<any, null>(
    `/admin/hosp/hospital/updateStatus/${id}/${status}`
  )
}
